<template>
  <el-dialog
    :visible="visible"
    :title="title"
    class="add-catalog-dialog"
    align-center
    @close="closeDialog"
  >
    <el-form
      :model="catalogForm"
      :rules="catalogRules"
      ref="catalogFormRef"
      label-width="90px"
    >
      <el-form-item label="目录名称" prop="catalogName">
        <el-input v-model="catalogForm.catalogName" />
      </el-form-item>
      <el-form-item label="上级目录" prop="parentCatalog">
        <el-input v-model="catalogForm.parentCatalog" />
      </el-form-item>
      <el-form-item label="目录图标" prop="catalogIcons">
        <Vue3IconPicker
          @change="handleIconPickChange"
          v-model="catalogForm.catalogIcon"
          placeholder="请选择"
          :clearable="true"
          :displaySearch="false"
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="onSubmit"> 确定 </el-button>
        <el-button @click="closeDialog">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
// import type { FormInstance, FormRules } from 'element-plus'
// import { Vue3IconPicker } from 'vue3-icon-picker'
// import 'vue3-icon-picker/dist/style.css'

defineProps({
  visible: {
    type: Boolean,
    default: false,
  },
  title: {
    type: String,
    default: '新增菜单',
  },
})

const emit = defineEmits(['closeDialog'])

const closeDialog = () => {
  emit('closeDialog')
}

const catalogForm = reactive({
  catalogName: '',
  parentCatalog: '',
  catalogIcon: '',
})

const catalogFormRef = ref()

const catalogRules = reactive({
  catalogName: [
    {
      required: true,
      message: '目录名称不能为空',
      trigger: 'blur',
    },
  ],
  parentCatalog: [
    {
      required: true,
      message: '父级目录不能为空',
      trigger: 'blur',
    },
  ],
  catalogIcons: [
    {
      required: true,
      message: '请选择目录图标',
      trigger: 'change',
    },
  ],
})

const onSubmit = () => {
  // catalogFormRef.value?.validate((valid) => {
  //   if (valid) {
  //   }
  // });
}

const handleIconPickChange = (e: any) => {
  console.log(e)
  console.log(catalogForm)
}
</script>

<style lang="scss">
.add-catalog-dialog {
  //width: 762px;
  //height: 704px;
  //background: #ffffff;
  border-radius: 4px;

  .el-dialog__header {
    border-bottom: 1px solid #e5e5e5;

    .el-dialog__title {
      width: 64px;
      height: 16px;
      font-size: 16px;
      font-weight: bold;
      color: #27475f;
    }
  }

  .el-form {
    margin-bottom: 336px;
    .el-form-item {
      min-height: 42px;
      margin-bottom: 21px;
      align-items: center;
    }

    .el-select {
      width: 100%;
    }
  }

  .el-dialog__footer {
    padding-top: 30px;
    border-top: 1px solid #e5e5e5;
  }

  .dialog-footer {
    width: 100%;
    height: 100%;
    text-align: center;
  }
}
</style>
